﻿using FoodModel;
using J.FoodRepository.InterFace;
using SqlSugar;
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace J.FoodRepository.Impl
{
    public class SpecificationRepository : BackRepository<SpecificationModel>, ISpecificationRepository
    {
        public SpecificationRepository(ISqlSugarClient db) : base(db)
        {
        }
        /// <summary>
        /// 菜品规格添加
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> SpecificationAdd(SpecificationModel model)
        {
            return await base.AddAsync(model);
        }
        /// <summary>
        /// 菜品规格反填
        /// </summary>
        /// <returns></returns>
        public async Task<List<SpecificationModel>> SpecificationBack(int id)
        {
            return await base.GetAllAsync();
        }
        /// <summary>
        /// 菜品规格分类显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<SpecificationModel>> Specificationclassify()
        {
            var list = await base.GetAllAsync();

            foreach (var item in list)
            {
                var separatedValues = item.Separate.Split(','); // 使用逗号作为分隔符
            }

            return list;
        }

        /// <summary>
        /// 菜品规格删除
        /// </summary>
        /// <param name="id"></param>
        /// <returns></returns>
        public async Task<int> SpecificationDelete(string id)
        {
            var ids = id.Split(',');
            var list = await base.GetAsync(propa => ids.Contains(propa.SpecificationId.ToString()));
            foreach (var item in list)
            {
                base.DeleteAsync(item.SpecificationId);
            }
            return list.Count;
        }

        /// <summary>
        /// 菜品规格显示
        /// </summary>
        /// <returns></returns>
        public async Task<List<SpecificationModel>> SpecificationShow()
        {
            return await base.GetAllAsync();
        }
        /// <summary>
        /// 菜品规格修改
        /// </summary>
        /// <param name="model"></param>
        /// <returns></returns>
        public async Task<int> SpecificationUpDate(SpecificationModel model)
        { 
            return await base.UpdateAsync(model);
        }
    }
}
